//
//  ViewController.m
//  02-在iOS中执行HTML代码
//
//  Created by J on 16/2/18.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIWebViewDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic)  UIActivityIndicatorView *activiyView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

//    NSURL* url = [NSURL URLWithString:@"http://www.xianhua.cn/m/?u=318719"];
    NSURL* url = [[NSBundle mainBundle]URLForResource:@"xianhua.html" withExtension:nil];

    NSURLRequest* request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
    
    self.webView.scrollView.hidden = YES;
    self.webView.backgroundColor = [UIColor grayColor];
    
    UIActivityIndicatorView* activiyView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [activiyView startAnimating];
    activiyView.center = self.view.center;
    [self.webView addSubview:activiyView];
    self.activiyView = activiyView;
    
    


}


- (void)webViewDidFinishLoad:(UIWebView *)webView{
//    //改变标题
//    NSString* str1 = @"var h1 = document.getElementsByTagName('h1')[0];"
//                    "h1.innerHTML='大神一期鲜花网';";
//
//    [webView stringByEvaluatingJavaScriptFromString:str1];
//    //删除尾部
////    NSString* str2 = @"var h1 = document.getElementById('footer');"
////    "h1.remove();";
//    NSString* str2 = @"var h1 = document.getElementById('footer').remove();"
//    "document.getElementsByClassName('detail_btns2')[0].remove();";
//    //    "h1.remove();";";//写法2
//    
////    NSString* str2 = @"var h1 = document.getElementsByClassName('detail_btns2')[0];"
////    "h1.remove();";//移除底部广告栏 [0]取数组第0个元素
//    [webView stringByEvaluatingJavaScriptFromString:str2];
//
//    //拿出所有的网页内容
//    NSString* str3 = @"document.body.outerHTML";
//    NSString* html = [webView stringByEvaluatingJavaScriptFromString:str3];
//    NSLog(@"%@",html);
//    
//    
    self.webView.scrollView.hidden = NO;
    self.activiyView.hidden = YES;
    
    
}


@end
